home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Disc to the Future 2
/
Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin
/
MAC
/
THINKC
/
4_0
/
HYPERXCM
/
XCMDUTIL.C
< prev
next >
Wrap
Text File
|
1991-10-22
|
4KB
|
122 lines
/*
⌐ 1991 Dick Guertin
XCmd Utilities by Gary Bond & Sioux Lacy
*/
#include <MacTypes.h>
#include <string.h>
#include "HyperXCmd.h"
#include "XCmdUtil.h"
/*----------------------------------------------------------------
* This utility sets a return string for HyperCard.
*---------------------------------------------------------------*/
void Fail (paramPtr, str)
XCmdBlockPtr paramPtr;
char *str;
{
paramPtr->returnValue = (Handle) CopyStrToHand(str);
return;
} /*- proc-end: Fail -*/
/*----------------------------------------------------------------
* This utility returns the parameter count, error if not in range.
*---------------------------------------------------------------*/
short GetParamCount (paramPtr, min, max)
XCmdBlockPtr paramPtr;
short min, max;
{ short count;
count = paramPtr->paramCount;
if ((count > max) || (count < min))
count = -1;
return (count);
} /*- proc-end: GetParamCount -*/
/*----------------------------------------------------------------
* This utility returns the parameter count, error if not in range.
*---------------------------------------------------------------*/
short CheckParamCount (paramPtr, amount)
XCmdBlockPtr paramPtr;
short amount;
{ return (GetParamCount(paramPtr, amount, amount));
} /*- proc-end: CheckParamCount -*/
/*----------------------------------------------------------------
* This utility allocates heapspace and copies string into it.
*---------------------------------------------------------------*/
Handle CopyStrToHand (str)
char *str;
{ Handle newHndl;
newHndl = (Handle) NewHandle((long)(strlen(str) + 1));
strcpy((char*)(*newHndl), str);
return (newHndl);
} /*- proc-end: CopyStrToHand -*/
/*----------------------------------------------------------------
* This utility makes a callback to HyperCard to convert a string
* to an unsigned long integer. It take a handle to a C-string.
*---------------------------------------------------------------*/
long HandleToNum (paramPtr, hndl)
XCmdBlockPtr paramPtr;
Handle hndl;
{ char str[32];
long num;
strcpy(str, *hndl);
num = StrToLong(paramPtr, (Str31*)ToPstr(str));
return (num);
} /*- proc-end: HandleToNum -*/
/*----------------------------------------------------------------
* This utility copies the string pointed to by a handle into a
* character array, converts it from C to Pascal format.
* Note that the C string is overwritten by the Pascal string.
*---------------------------------------------------------------*/
void HandleToPstr (str, hndl)
Str255 str;
Handle hndl;
{
strcpy((char*)str, *hndl);
ToPstr((char*)str);
} /*- proc-end: HandleToPstr -*/
/*----------------------------------------------------------------
* This utility converts a Pascal string to a C string.
* Note that the Pascal string is overwritten in the process.
*---------------------------------------------------------------*/
char* ToCstr (str)
char *str;
{ unsigned char length, i;
length = str[0];
for (i=0; i<=length; ++i)
str[i] = str[i+1]; /*- Move string left -*/
str[length] = '\0';
return (str);
} /*- proc-end: ToCstr -*/
/*----------------------------------------------------------------
* This utility converts a C string to a Pascal string.
* Note that the C string is overwritten in the process.
*---------------------------------------------------------------*/
char* ToPstr (str)
char *str;
{ unsigned char length, i;
for (i=0; str[i]!=0; ++i);
length = i;
while (i--)
str[i+1] = str[i]; /*- Move string right -*/
str[0] = length;
return (str);
} /*- proc-end: ToPstr -*/